package com.shujia.spring.mvc.dao;

import com.shujia.spring.mvc.bean.User;
import com.shujia.spring.mvc.util.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    static Connection conn = JDBCUtil.getConn();
    static PreparedStatement ps=null;
    static ResultSet rs=null;
    @Override
    public User selectUser(String username) {
        User user = null;
        String sql = "select * from user where username=?";
        try {
            ps = conn.prepareStatement(sql);
            ps.setString(1,username);
            rs = ps.executeQuery();
            while (rs.next()){
                user = new User();
                user.setUsername(rs.getString("username"));
                user.setPassword(rs.getString("password"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //JDBCUtil.closeAll(conn,ps,rs);
        return user;
    }
}
